/**
 * Created by dongchen on 16/4/25.
 */
define(['jquery','ModelBase', 'ajaxUtil', 'fileUpload'], function ($,ModelBase, ajaxUtil) {

    var model = ModelBase.extend({

        uploadAddMobiles: function (elem) {
            var dtd = $.Deferred();

            $.ajaxFileUpload({
                url: 'admin/mobiles/add',
                type: "post",
                secureuri: false,
                fileElementId: $(elem).attr('id'),
                dataType: 'json',
                success: function (res) {
                    dtd.resolve(res);
                },
                error: function (res) {
                    dtd.resolve(res);
                }
            });
            return dtd.promise();
        },

        uploadInitMobiles : function(elem, queryParams){
            var dtd = $.Deferred();

            $.ajaxFileUpload({
                url: 'admin/mobiles/init',
                type: "post",
                data: queryParams,
                secureuri: false,
                fileElementId: $(elem).attr('id'),
                dataType: 'json',
                success: function (res) {
                    dtd.resolve(res);
                },
                error: function (res) {
                    dtd.resolve(res);
                }
            });
            return dtd.promise();
        },

        getDiscount : function(){
            return ajaxUtil.doJsonpRequest_v2('/api/discount');
        },

        saveDiscount : function(data){
            return ajaxUtil.doPostJsonpRequest_v2('/api/discount', data)
        }
    });

    return model;
});